#include <bits/stdc++.h>;

using namespace std;
const int N = 200001;
int T,n,ans;
struct Node
{
    int s;
    bool color;
}a[N];
int c[N];
//int dp[N][2];
void dfs(int i)
{
    if(i>n)
    {
        int k=0;
        for(int i=0;i<n;i++)
            k+=c[i];
        ans = max(ans,k);
        return ;
    }
    a[i].color = 1;
    for(int j=i-1;j>=0;j--)
    {
        if(a[j].color==a[i].color&&a[j].s==a[i].s)
        {
            c[i]=a[j].s;
            break;
        }
        c[i] = 0;
    }
    dfs(i+1);

    a[i].color = 0;
    for(int j=i-1;j>=0;j--)
    {
        if(a[j].color==a[i].color&&a[j].s==a[i].s)
        {
            c[i]=a[j].s;
            break;
        }
        c[i] = 0;
    }
    dfs(i+1);
    return ;
}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    scanf("%d",&T);
    while(T--)
    {
        ans = 0;
        c[0] = 0;
        scanf("%d",&n);
        for(int i=0;i<n;i++)
            scanf("%d",&a[i]);
        dfs(1);
        printf("%d\n",ans);
    }
    return 0;
}
